package com.chensf.studydemo.guide.animation

import android.os.Bundle
import android.transition.*
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import com.chensf.studydemo.R

class SimpleTransitionActivity2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
        setContentView(R.layout.activity_simple_transition2)
//        setupWindowTransition()
        setupShareAnimations()
    }

    private fun setupShareAnimations(){
        val transitionSet = TransitionSet()
        transitionSet.addTransition(ChangeImageTransform())
        transitionSet.addTransition(ChangeBounds())

        window.sharedElementEnterTransition = transitionSet
    }

    private fun setupWindowTransition() {
        val fade = Fade()
        fade.duration = 300
        val slide = Slide()
        slide.duration = 300
        window.allowEnterTransitionOverlap = true
        window.enterTransition = fade
        window.returnTransition = slide
    }

    override fun onBackPressed() {
        finishAfterTransition()
    }
}